//封装临时游客身份的模块
import { v4 as uuidv4 } from 'uuid'
export const getUUID = () => {
    //生成一个随机的字符串，且每次执行不发生变化，游客身份持久储存
    //先从本地存储获取uuid
    let uuid_token = localStorage.getItem('UUIDTOKEN')
    //如果没有生成一个临时游客身份
    if (!uuid_token) {
        uuid_token = uuidv4()
        //本地存储一次
        localStorage.setItem('UUIDTOKEN', uuid_token)
    }
    //返回id
    return uuid_token
}

//对外暴露一个储存token的函数
export const setToken = (token) => {
    localStorage.setItem('TOKEN', token)
}

//清除token
export const removeToken = () => {
    localStorage.removeItem('TOKEN')
}